package com.bifrost.repository;

import com.bifrost.entity.PlanItem;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

/**
 * @author Lee
 * Create Class on 2018/8/13
 * @com.bifrost.repository
 * @wechat-mall
 */
public interface PlanItemRepository extends JpaRepository<PlanItem,Long>{

    @Query(nativeQuery = true , value = "UPDATE PLAN_ITEM SET INVENTORY_AVAILABLE=INVENTORY_AVAILABLE-?2 WHERE PLANITEM_ID=?1 AND INVENTORY_AVAILABLE>=?2")
    @Modifying
    int hitCustomer(Long planItemId , Integer quantity);

    @Query(nativeQuery = true , value = "SELECT SUM(plan_item.INVENTORY_AVAILABLE) from plan_item where PLAN_ID=?1")
    Integer quantity(Long planId);
}
